<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<link rel="stylesheet" href="/css/font.css">
		<link rel="stylesheet" href="/css/xadmin.css">
		<script type="text/javascript" src="/js/jquery.min.js"></script>
		<script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="/js/xadmin.js"></script>
		<style>
			form {
				margin-top: 10px;
			}
			
		</style>
	</head>
	<body>
		<form class="layui-form" id="saveCourseForm">
			<div class="layui-form-item">
				<label class="layui-form-label"><font color="red" size="3">*</font>课程代码</label>
				<div class="layui-input-block">
					<input type="number" name="courseNo" required lay-verify="required|courseNo" placeholder="7-10位数字，且不能出现空格" autocomplete="off" class="layui-input">
					<input type="hidden" name="type" value="3"/>
					<input type="hidden" name="majorNo" value="0"/>
				</div>
			</div>
			<div class="layui-form-item">
                <label class="layui-form-label"><font color="red" size="3">*</font>课程名称</label>
                <div class="layui-input-block">
                    <input type="text" name="courseName" required lay-verify="required|courseName" placeholder="2-25个字符，且不能出现空格" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red" size="3">*</font>课程学分</label>
                <div class="layui-input-block">
                    <input type="number" name="credit" required lay-verify="required|credit" placeholder="1~2位数字" autocomplete="off" class="layui-input">
                </div>
            </div>
	        <div class="layui-form-item">
               <label class="layui-form-label"><font color="red" size="3">*</font>上课周期</label>
               <div class="layui-input-block">
                   <input type="text" name="time" required lay-verify="required|time" placeholder="开始周-结束周，数字中间‘-’做分隔" autocomplete="off" class="layui-input">
               </div>
            </div>
			<!-- <div class="layui-form-item">
				<label class="layui-form-label">排序号</label>
				<div class="layui-input-block">
					<input type="number" name="sort" required lay-verify="required|sort" placeholder="1-5位数字，降序排列" autocomplete="off" class="layui-input" value="1">
				</div>
			</div> -->
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo" type="button">立即提交</button>
				</div>
			</div>
		</form>
		
		<script>
			layui.use(['form', 'layedit', 'laydate'], function(){
				var form = layui.form
				,layer = layui.layer
				
				form.verify({
                    courseNo: [/^[\S]{7,10}$/,'7-10位数字，且不能出现空格'],
                    courseName: [/^[\S]{2,25}$/,'2-25个字符，且不能出现空格'],
                    credit: [/^[\S]{1,2}$/,'1~2位数字'],
                    time:[/[\d]+\-[\d]+$/,'开始周-结束周，数字中间‘-’做分隔'],
                    sort: function(value) {
                        if(value.length > 5) {
                            return "1-5位数字";
                        }
                    },
                });
			
				//监听提交
				form.on('submit(formDemo)', function(data){
					$.ajax({
	                    url : "/sys/school/course/saveCourse",
	                    type : "post",
	                    data : $("#saveCourseForm").serializeArray(),
	                    success : function(result) {
	                        if (result.state) {
	                            layer.msg('保存成功！', {icon: 1,time: 1000}, function(){
									// 1.先得到当前iframe层的索引
									var index = parent.layer.getFrameIndex(window.name); 
									// 2.再执行关闭 
									parent.layer.close(index); 
									// 调用父页面的方法
									window.parent.updateData();
	                            });
	                        } else {
	                            layer.msg(""+result.msg, {icon: 5});
	                        }
	                    }
	                });
				});
			});
		</script>
	</body>
</html>
